<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>管理员编辑审批人</title>
    <script type="text/javascript">
      Ext.onReady(function(){
        var auditorId = <%= params[:id] %>

        var departmentTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item">', '{name}', '</div></tpl>');
        //部门
        var departmentStore = new Ext.data.Store({
          proxy:new Ext.data.HttpProxy({url:'/department/getDepartments'}),
          reader:new Ext.data.JsonReader({
          }, [
            {name:'name'},
            {name:'id'}
          ])
        });
        
        //部门
        var department = new Ext.form.ComboBox({
          store: departmentStore,
          fieldLabel: '所属部门',
          allowBlank: false,
          blankText: "部门必须选择",
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'department_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '95%',
          //pageSize: 10,
          //hideTrigger: false,
          tpl: departmentTemplate,
          readOnly:false,
          minChars: 0,
          itemSelector: 'div.search-item',
          selectOnFocus:true
        });

        var auditorType = new Ext.form.RadioGroup({
          //width : 220,
          fieldLabel: '审批类型',
          //hideLabel:true,
          //style:'margin-left:100px;margin-top:20px',
          columns : 2,
          anchor: '100%',
          vertical :false,
          items:[
            {boxLabel:'设备',inputValue:'0',name:'auditor_type',checked:true},
            {boxLabel:'家具',inputValue:'1',name:'auditor_type'}
          ]
        });

        //系统角色
        var roleStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/admin/getAllRoles?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'name'
            }])
        });
        roleStore.load();
        
        //角色
        var role = new Ext.form.ComboBox({
          store: roleStore,
          fieldLabel: '系统角色',
          allowBlank: false,
          blankText: "角色必须选择",
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'role_id',//如果不想提交displayField，则在这儿指定要提交的Key，value就是valueField．
          emptyText: '请选择...',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '95%',
          readOnly:false,
          minChars: 0,
          editable:false
        });
        
        var editAuditorForm=new Ext.form.FormPanel({
          width:750,
          labelAlign: 'right',
          url:'/auditor/update',
          buttonAlign:'center',
          autoHeight:true,
          fileUpload: true,
          bodyStyle: 'padding:5px',
          labelWidth:130,
          waitMsgTarget: true,
          frame: true,
          reader:new Ext.data.JsonReader({
          },[
            {name:'id'},
            {name:'login_id'},
            {name:'name'},
            {name:'mobile'},
            {name:'phone'},
            {name:'unit_price_ceiling'},
            {name:'amount_ceiling'},
            {name:'email'},
            {name:'role_id'},
            {name:'department_id'},
            {name:'is_admin'},
            {name:'is_chief'}
          ]),
          items:[{
              layout:'column',
              items:[{
                  columnWidth:.5,
                  layout:'form',
                  items:[{
                      xtype:'hidden',
                      name:'id'
                    },{
                      xtype:'textfield',
                      fieldLabel: '审批人编号',
                      name: 'login_id',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'textfield',
                      fieldLabel: '审批人姓名',
                      name:'name',
                      allowBlank:false,
                      anchor:'90%'
                    },role,{
                      xtype:'textfield',
                      fieldLabel: '移动电话',
                      name: 'mobile',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'textfield',
                      fieldLabel: 'Email',
                      name: 'email',
                      allowBlank:false,
                      anchor:'90%'
                    },{
                      xtype:'numberfield',
                      fieldLabel: '可管理单价上限',
                      name: 'unit_price_ceiling',
                      allowBlank:false,
                      anchor:'90%'
                    }]
                },{
                  columnWidth:.5,
                  layout:'form',
                  items:[{
                      xtype:'radiogroup',
                      fieldLabel: '是否为超级管理员',
                      name:'is_admin',
                      height:22,
                      items: [
                        {boxLabel: '是', name: 'is_admin', inputValue: '1'},
                        {boxLabel: '否', name: 'is_admin', inputValue: '0'}
                      ]
                    },{
                      xtype:'radiogroup',
                      fieldLabel: '是否为处长',
                      name:'is_chief',
                      height:22,
                      items: [
                        {boxLabel: '是', name: 'is_chief', inputValue: '1'},
                        {boxLabel: '否', name: 'is_chief', inputValue: '0'}
                      ]
                    },auditorType,{
                      xtype:'textfield',
                      fieldLabel: '固定电话',
                      name: 'phone',
                      allowBlank:false,
                      anchor:'90%'
                    },department,{
                      fieldLabel: '可管理总额上限',
                      xtype:'numberfield',
                      name: 'amount_ceiling',
                      allowBlank:false,
                      anchor:'90%'
                    }]
                }]
            }],
          buttons:[{
              id:'save',
              text:'确定',
              handler: function(){
                // check form value
                if (editAuditorForm.form.isValid()) {
                  Ext.getCmp('save').setDisabled(true);
                  editAuditorForm.form.submit({
                    method: 'post',
                    waitMsg: '正在保存审批人信息...',
                    success: function(result, response){
                      if (response.result.info == "success") {
                        //添加成功后，隐藏窗口，并刷新Grid
                        editAuditorWin.destroy();
                      }
                      else {
                        Ext.getCmp('save').setDisabled(false);
                        Ext.MessageBox.alert('消息', response.result.info);
                      }
                    },
                    failure: function(result, response){
                      Ext.getCmp('save').setDisabled(false);
                      Ext.MessageBox.alert('提示', result.responseText);
                    }
                  });
                }
                else {
                  Ext.MessageBox.alert('错误提示', '请按要求填写必输选项.');
                }
              }
            },{
              text:'取消',
              handler:function(){
                editAuditorWin.destroy();
              }
            }]
        });

        departmentStore.load({callback: function(record, options, success){
            if(success){
              editAuditorForm.form.load({
                url: '/auditor/edit?id=' + auditorId,
                success: function(form, action){
                },
                failure: function(form, action){
                  Ext.MessageBox.alert('提示信息', '信息加载失败');
                }
              });
            }else{
              Ext.Msg.alert('操作','失败！');
            }
          }});

        
        editAuditorForm.render('edit_auditor_form');
      })
    </script>
  </head>
  <body>
    <div id="edit_auditor_form"></div>
  </body>
</html>
